function sdirmat=drawDir(alphv); 
%Generate draws from the Dirichlet distribution
%for a ns x 1 matrix xmat 
%Possible a column of Markov counts 
%   generated by countswitch.m 
%alphv (nsx1) vector of alphas 
[ns,nc]=size(alphv);
if nc > ns 
    alphv=alphv'; 
    ns=nc;
end    
sdirmat=zeros(ns,1); 
xg=gamrnd(alphv,ones(ns,1)); 
if sum(xg) < eps 
    sdirmat=ones(ns,1)./ns 
else
    sdirmat=xg./sum(xg); 
end 

